package com.xspace.android.xafcommon.util;

import android.text.TextUtils;

import java.io.File;


public class WorkLogConstant {
    //sd卡开关
    public static final boolean isSdCardDataEnabled = true;

    /****************************************
     * 本地测试begin
     *****************************************/
//	public final static String AddressLL = "http://192.168.1.67:8087";//李丽测试
    //	public final static String AddressLL = "http://192.168.1.138:8080";//liuchen测试
//    public static String AddressLL = "http://192.168.1.129:8068";//liujian测试
    //	public final static String AddressLL = "http://192.168.1.159:8080";//lishuang测试
//    	public  static String AddressLL = "http://192.168.1.174:8080";//chu测试
//    	public  static String AddressLL = "http://192.168.1.119:8068";//xiao
//    public static String AddressLL = "http://192.168.1.160:8080";//lanxi
    //    	public final static String AddressLL = "http://192.168.1.160:8080";//fan测试
    //	public final static String AddressLL = "http://192.168.1.128:8080";//chenzhang测试
    //	public final static String AddressLL = "http://192.168.1.52:8080";//changbin测试
    //	public final static String AddressLL = "http://192.168.0.179:8080";//;lixiaofeng测试
    //	public final static String AddressLL = "http://192.168.1.124:8083";//;lixinran测试
//    public static String UnZipHtmlBaseDir = "wwwtest";
    /****************************************本地测试 end *****************************************/

    /***************************************
     * 内网测试 begin
     *****************************************/

////    public final static String AddressLL = "http://222.173.29.164:8068"; //旧表单地址
//    public final static String AddressLL = "http://192.168.1.50:8314"; //新表单地址
////
//////     http://192.168.1.67:8087 http://222.173.29.164:8068/AFMMobile/
//
//    public static String UnZipHtmlBaseDir = "wwwtest";


    /****************************************内网测试 end*****************************************/


    /****************************************
     * 现网发布 begin
     *****************************************/
    public final static String AddressLL = Constants.AddressLL;
    /****************************************
     * 现网发布 end
     *****************************************/


    //共同
    public static String AFMMobile = "/AFMMobile/";
    public static String workSign_suffix = "oa/usersign/attence_signin.html";
    public static String workSignCalendar = "oa/usersign/attence_calendar.html";
    public static String addWorkLogMianyiForm_suffix = "breed/shengzhumianyidangan.html?&object_id=";
    public static String selectPaifaWorkLogForm_suffix = "breed/serviceobj_table_list.html?&serviceobjid=";
    public static String addWorkLogForm_suffix = "breed/dongwumianyi.html?&object_id=";
    public static String MyOfflineDataUrl_suffix = "offline/offline_data.html";
    public static String MyOfflineFormUrl_suffix = "offline/offline_form.html";
    public static String MyServiceObjectFormUrl_suffix = "myservice/service.html";
    public static String XuMuAdminFormUrl_suffix = "breed/table_list.html";
    public static String jianguan_zonghe_Url_suffix = "oa/jianguanzonghetongji.html";
    public static String MyServiceAddFormUrl_suffix = "myservice/add_service.html";


    public static String workSign = AddressLL + AFMMobile + workSign_suffix;
    public static String addWorkLogMianyiForm = AddressLL + AFMMobile + addWorkLogMianyiForm_suffix;
    public static String selectPaifaWorkLogForm = AddressLL + AFMMobile + selectPaifaWorkLogForm_suffix;
    public static String addWorkLogForm = AddressLL + AFMMobile + addWorkLogForm_suffix;
    public static String MyOfflineDataUrl = AddressLL + AFMMobile + MyOfflineDataUrl_suffix;
    public static String MyOfflineFormUrl = AddressLL + AFMMobile + MyOfflineFormUrl_suffix;
    public static String MyServiceObjectFormUrl = AddressLL + AFMMobile + MyServiceObjectFormUrl_suffix;
    public static String XuMuAdminFormUrl = AddressLL + AFMMobile + XuMuAdminFormUrl_suffix;
    public static String jianguan_zonghe_Url = AddressLL + AFMMobile + jianguan_zonghe_Url_suffix;
    public static String MyServiceAddFormUrl = AddressLL + AFMMobile + MyServiceAddFormUrl_suffix;

    //帮助文档
    public final static String HELP_DOC = AddressLL + AFMMobile + "help/index.html";
    //散户数据
    public final static String OfflineAnimalBySanHu = AddressLL + AFMMobile
            + "dictOffAction!getOfflineAnimalBySanHu.action";
    //获取字典离线数据
    public final static String OfflineDictData = AddressLL + AFMMobile
            + "dictOffAction!getOfflineDictData.action?v=4";

    //获取屠宰离线数据
    public final static String offTuZaiOffAction = AddressLL + AFMMobile
            + "offTuZaiOffAction!queryOffTuZai.action?v=4";
    //获取我的服务对象离线数据
    public final static String OfflineMyServiceData = AddressLL + AFMMobile
            + "myServiceOffAction!getOfflineData.action?v=4";
    //获取物种疾病接口
    public final static String OfflineDiseaseData = AddressLL + AFMMobile
            + "dictOffAction!getOfflineDiseaseData.action?v=4";
    //获取服务对象分类接口
    public final static String OfflineSerObjCategoryData = AddressLL + AFMMobile
            + "dictOffAction!loadOfflineSerObjCategoryData.action?v=4";
    //获取生猪数据库数据接口
    public final static String OfflineQueryShengZhuOffData = AddressLL + AFMMobile
            + "shengZhuOffAction!queryShengZhuOffData.action?v=4";
    //获取免疫检疫专项数据库数据接口
    public final static String OfflineQueryMianyiOffData = AddressLL + AFMMobile
            + "mianYiOffAction!queryMianYiOffData.action?v=4";
    //耳标号离线数据
    public final static String OfflineEartagOffData = AddressLL + AFMMobile
            + "shengZhuOffAction!queryEartagOffData.action?v=4";
    //获取服务对象分类和具体分类配置好的品种
    public final static String OfflineserviceObjPinZhongAction = AddressLL + AFMMobile
            + "serviceObjPinZhongAction!getOfflineData.action?v=4";
    //获取春秋防疫的离线数据db
    public final static String OfflineChunQiuFYDB = AddressLL + AFMMobile
            + "offChunQiuSettingAction!getChunQiuSettingOffLineMafDb.action?v=4";
    //获取璧山数据db
    public final static String OfflineBishanDB = AddressLL + AFMMobile
            + "mafOffLineAction!getBSOffLineBSDb.action?v=4";
    public final static String OfflineMafDB = AddressLL + AFMMobile
            + "mafOffLineAction!getMafOffLineMafDb.action?v=4";
    /*获取签到信息*/
    public final static String UserSignInfoQueryClassInfo = AddressLL + AFMMobile
            + "attenceAction!queryClassInfo.action?";
    /*上传定位信息*/
    public final static String UserSignInfoAddTrail = AddressLL + AFMMobile + "trailAction!addTrail.action";

    public static final String SpecialMianyiWork = "免疫专项工作";
    public static final String SpecialJianyiWork = "检疫专项工作";
    public static boolean IsNeedRefreshTodoList = false;

    public static final String FARMER_FORM_JIYI = "0";
    public static final String FARMER_FORM_JIYI_HANDLER_TABLE = "breed_animal_checkrecord";
    public static final String FARMER_FORM_MIANYIN = "1";
    public static final String FARMER_FORM_JIANDU = "2";
    public static final String FARMER_FORM_CHUQIN = "3";
    public static final String FARMER_FORM_XUNJIAN = "4";

    public static final String FARMER_FORM_SHUICHAGUIMO = "5";
    public static final String FARMER_FORM_SHUICHAZHONGMIAO = "6";
    public static final String FARMER_FORM_SHENGZHU = "7";
    public static final String FARMER_FORM_SHENGTAI = "8";
    /**
     * 本地解压目录
     **/
    public static final String ZIP_ADDRESS = AppConstant.OFFLINE_FORM;


    public static String getMyWorkUrl(String url) {
        String remoteUrl;
        if (url.startsWith("/")) {
            remoteUrl = AddressLL + AFMMobile.substring(0, AFMMobile.length() - 1) + url;
        } else {
            remoteUrl = AddressLL + AFMMobile + url;
        }
        if (!isSdCardDataEnabled) {
            return remoteUrl;
        } else {
            //请求本地
            String path = "";
            if (url.startsWith(File.separator)) {
                path = ZIP_ADDRESS + Constants.UnZipHtmlBaseDir + url;
            } else {
                path = ZIP_ADDRESS + Constants.UnZipHtmlBaseDir + File.separator + url;
            }
            //判断本地有没有此路径
            String filePath = path;
            if (path.contains("?")) {
                filePath = path.substring(0, path.indexOf("?"));
            }
            File file = new File(filePath);
            LogUtil.v("worklogconstant", "getMyWorkUrl>>>sd file.exists:" + file.exists() + " path:" + path);
            if (file.exists()) {
                url = "file:///" + path;
                return url;
            } else {
//                return "file:///android_asset/index.html";
                return "";
//                return remoteUrl;
            }
        }
    }

    /**
     * 方法描述 : 检疫免疫 未处理的表单
     *
     * @param url
     * @return
     */
    public static String getMyJyUrl(String url) {
        if (!isSdCardDataEnabled)
            return url;
        if (TextUtils.isEmpty(url)) {
            return url;
        }
        if (url.contains("AFMMobile")) {
            url = url.substring(url.indexOf("AFMMobile") + "AFMMobile".length(), url.length());
            LogUtil.d("wubaojie>>>getMyJyUrl: 全路径地址切割后url:" + url);
        }
        if (url.startsWith(File.separator)) {
            url = ZIP_ADDRESS + Constants.UnZipHtmlBaseDir + url;
        } else {
            url = ZIP_ADDRESS + Constants.UnZipHtmlBaseDir + File.separator + url;
        }
        String filePath = url;
        if (filePath.contains("?")) {
            filePath = filePath.substring(0, filePath.indexOf("?"));
        }
        File file = new File(filePath);
        if (file.exists()) {
            url = "file:///" + url;
        }
        LogUtil.d("wubaojie>>>getMyJyUrl: 组装后url:" + url);
        return url;
    }

    /**
     * 方法描述 :检疫 填写记录单 dongwumianyi
     *
     * @return
     */
//    public static String getJyWriteUrl() {
//        if (!isSdCardDataEnabled)
//            return addWorkLogForm;
//        String url = "breed/dongwumianyi.html";/*?&object_id=*/
//        File file = new File(ZIP_ADDRESS + Constants.UnZipHtmlBaseDir + "/" + url);
//        LogUtil.v("worklogconstant", "getJyWriteUrl>>>sd file.exists:" + file.exists());
//        if (file.exists()) {
//            url = "file:///mnt/sdcard/" + AppConstant.OFFLINE_HTML_ADDRESS + "/" + Constants.UnZipHtmlBaseDir + "/" +
//                    url + "?&object_id=";
//        }
//        return url;
//    }

    /**
     * 方法描述 :免疫 填写记录单 shengzhumianyidangan
     *
     * @return
     */
    public static String getMyWriteUrl() {
        String url = addWorkLogMianyiForm;
        if (url.contains("breed")) {
            url = ZIP_ADDRESS + Constants.UnZipHtmlBaseDir + "/" + addWorkLogMianyiForm
                    .substring(addWorkLogMianyiForm.indexOf("breed"), addWorkLogMianyiForm.length());
        }
        return url;
    }
}
